#!/bin/bash
set -e -x

cd /io/ && rm -rf build dist # && ./configure && make && make install 

# Compile wheels
rm -rf /io/wheelhouse/ # &&  cd /io/CRFPP && make clean && ./configure && make install 

rm -rf /opt/python/cp27*
rm -rf /opt/python/cp34*
rm -rf /opt/python/cp35*
rm -rf /opt/python/cp36*
rm -rf /opt/python/cp37*
rm -rf /opt/python/cp39*
rm -rf /opt/python/pp3*


for PYBIN in /opt/python/*/bin; do
    "${PYBIN}/pip" install -i https://pypi.tuna.tsinghua.edu.cn/simple -r /io/dev-requirements.txt
    "${PYBIN}/pip" wheel /io/ -w wheelhouse/
done

# Bundle external shared libraries into the wheels
for whl in wheelhouse/*.whl; do
    auditwheel repair "$whl" -w /io/wheelhouse/
done

# Install packages and test
for PYBIN in /opt/python/*/bin/; do
    "${PYBIN}/pip" install -i https://pypi.tuna.tsinghua.edu.cn/simple crfpy  --no-index -f /io/wheelhouse
    "${PYBIN}/python" -c "import CRFPP"
    # (cd "$HOME"; "${PYBIN}/nosetests" rectangle_08ms)
done

find /io/wheelhouse -name '*.whl' |grep -v many| grep -i linux |xargs rm -f
